<% @page_title = "多背一公斤 | #{h @group.title} - #{h @topic.title}" -%>

<% content_for :head do -%>
  <script type="text/javascript" src="/javascripts/thickbox.js"></script>
  <link rel="stylesheet" href="/stylesheets/thickbox.css" type="text/css" media="screen" />
<% end -%>

<% content_for :sidebar do -%>
  <h4><%= link_to "返回 #{h @group.title}", group_url(@group.id) %></h4>
  <h4><%= link_to "在 #{h @group.title} 写新话题", new_topic_url(@group.id) %></h4>
<% end -%>


<h3><%= h @topic.title %></h3>

<div class="span-12">
 	<div class="span-2"><%= avatar_for @topic.user, "large" %></div>
	<div class="span-9 large">
	  <%= link_to @topic.user.login, user_url(@topic.user.id) %>
	  <span class="tip">发布于： <%= show_datetime @topic.created_at %> 
	</div>
</div>
<div class="span-3 last">
<% if @topic.editable_by?(current_user) -%>
  <p style="text-align:right">
		<%= link_to "修改", edit_topic_url(@group.id, @topic.id) %>
		<%= link_to "删除", topic_url(@group.id, @topic.id), :method => 'delete', :confirm => "确定要删除么？" %>
	</p>
<% end -%>
</div>
<div class="clear"></div>
<div class="prepend-1"><%= @topic.content_html %></div>

<div class="span-15 prepend-1">
	<% if @posts.blank? -%>
  	<p>还没有回复，你要不要加盖一楼</p>
	<% end -%>
	<% @posts.each do |post| -%>
	<div style="margin-bottom:20px;">
	<div class="span-2 last">
		<%= avatar_for post.user, "large" %>
	</div>
	<div class="span-13 last">		
		<div class="span-11">
			<div class="comment_label">
				<span class="tip"><%= link_to post.user.login, user_path(post.user) %> 回复于: <%= show_date post.created_at %></span>
			</div>
		</div>
		<div class="span-2 last">
			<% if post.editable_by?(current_user) -%>
			<span class="comment_label">
				<%= link_to "修改", edit_post_url(@group.id, @topic.id, post.id) %>
				<%= link_to "删除", post_url(@group.id, @topic.id, post.id), :method => 'delete', :confirm => "确定要删除么？" %>
			</span>
			<% end -%>
		</div>
		<div class="span-13"><%= post.content_html %></div>
	</div>
	<div class="clear"></div>
	</div>
	<% end -%>
</div>

<% if logged_in? -%>
	<h3 class="nt">你的回复</h3>
	<% form_for :post, :url => posts_url(@group.id, @topic.id) do |f| -%>
  	<p><%= f.text_area :content, :rows => 6, :class => 'content_textarea' %></p>
	<p>
  <%#= link_to_r "+ 给回复添加图片", new_photo_url %>
	<%=image_tag 'loading.gif', :class=>'spinner', :style=>"display:none;"%>
	<%= link_to "+ 给回复添加图片", new_photo_url(:topic_id => @topic.id,
																				 :width => 600, :height => 400), 
																				 :class => "thickbox",
																				 :title => "添加图片" %>
	</p>

	<div id="photo4up"></div>

	<iframe id='photo4show' name="photo4show" style="width:1px;height:1px;border:0px" src="about:blank"></iframe>
	<br />
	<%= submit_tag "写好了，提交" %>
	<br />
	<br />
	<% end -%>
<% else -%>
  <%= link_to "登录", login_url %>后才可以回复
<% end -%>
